home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
Tutorial
/
Cookbook
/
17.plot
/
plotview.psw
< prev
Wrap
Text File
|
1995-06-12
|
4KB
|
195 lines
defineps createPSDefs()
/strx 20 string def
/stry 20 string def
/str 20 string def
/divx ( per division on x, ) def
/divy ( per division on y) def
/plotfont {
% width and height of viewing area on stack
% make font that is 3 percent of current size
scale
/Times-Roman findfont
0.03 scalefont setfont
} def
endps
defineps PSDrawAxis(float ac, x, y, w, h)
0.0 setlinewidth
ac setgray
% draw from edge of x to origin to tip of y
w x add y moveto
x y lineto
x y h add lineto
stroke
% now show the location of the origin
x y h 0.04 mul sub moveto
gsave % setup font coordinates
w h plotfont
x str cvs show
grestore % go back to program coordinates
x w add y h 0.04 mul sub moveto
gsave
w h plotfont
x w add str cvs % the end point
dup stringwidth neg exch neg exch rmoveto show
grestore
%
% move 1 percent to the left of the axis
x w 0.01 mul sub y moveto
gsave % set up font coordinates
90.0 rotate
h w plotfont
y str cvs show
grestore % restore program coordinates
x w 0.01 mul sub y h add moveto
gsave
90 rotate
h w plotfont
y h add str cvs % top end of y axis
dup stringwidth neg exch neg exch rmoveto show
grestore
endps
defineps PSWriteXLabel(float gray,x,y,w,h; char *lab)
% pass in the min and size of both axis along with the string
gsave
gray setgray
x w 2.0 div add %center position of axis
y h 0.04 mul sub % figure out ylocation
moveto
w h plotfont
(lab) stringwidth 2.0 div %halfo of the length of the string
neg 0 rmoveto %move back half
(lab)show
grestore
endps
defineps PSWriteYLabel(float gray,x,y,w,h; char *lab)
% pass in the min and size of both axis along with the string
gsave
gray setgray
x w 0.01 mul sub % location on xaxis
y h 2.0 div add % center of y axis
moveto
90.0 rotate
h w plotfont
(lab) stringwidth 2.0 div % half of length of string
neg 0 exch rmoveto % move down half
(lab)show
grestore
endps
defineps PSEnableInstance(float instcol)
gsave % save the original coordinate position
true setinstance
instcol setgray % allow user to set instance color
0.0 setlinewidth % set smallest possible line
endps
defineps PSDisableInstance()
%newinstance % remove last instance drawing
false setinstance %resume normal drawing
grestore % return to original gstate
endps
defineps PSDrawCrossHair(float startx, starty, minx, maxx, miny, maxy)
% minx, miny, maxx, maxy are the bounds of the page
% startx, starty is the point where the cursor is
/doright
{
startx strx cvs show
(,) show
starty stry cvs show
} def
/doleft
{
starty stry cvs
dup stringwidth neg exch neg exch
rmoveto
(,)
dup stringwidth neg exch neg exch
rmoveto
startx strx cvs
dup stringwidth neg exch neg exch
rmoveto
show show show
}def
%newinstance
startx miny moveto
startx maxy lineto
minx starty moveto
maxx starty lineto
stroke
startx starty dup .01 mul add moveto % go up 1% off access
gsave % we use seperate context so that font scaling is easier
%/Times-Roman findfont
/Courier findfont
maxx minx sub % make the view unit length
maxy miny sub % and unit height
scale
0.05 scalefont
setfont
maxx minx sub 2.0 div %calc center
startx lt % is start x to right of center
{doleft} {doright} ifelse % put text on wide side of cursor
grestore
%showpage
endps
defineps PSOverlayBox(float minx, maxx, miny, maxy)
%newinstance
gsave
0 setlinewidth
minx miny moveto
minx maxy lineto
maxx miny moveto
maxx maxy lineto
stroke
grestore
endps
defineps PSGridWrite(float textcol, gx, gy, minx, maxx, miny, maxy)
% write out the x and y grid values across the top
% for some reason, when going to the printer the literal strings must be in
% definintions ... not as literals in the code
gsave
textcol setgray
maxx minx sub 0.15 mul minx add % make it 15 percent across
maxy miny sub 1.01 mul miny add % make just above top
moveto
maxx minx sub % make the view a unit length
maxy miny sub % make it a unit height
plotfont
gx str cvs show
divx show
gy str cvs show
divy show
grestore
endps
defineps PSBox(float lc, lw, x, y, w, h)
% draw a box that starts at x,y and is w wide and h high
lc setgray
lw setlinewidth
x y moveto
x y h add lineto
x w add y h add lineto
x w add y lineto
x y lineto
stroke
endps
defineps PSfillrect(float x, y, xn, yn)
% fill a box with opposite corners x,y and xn,yn
x y moveto
x yn lineto
xn yn lineto
xn y lineto
x y lineto
fill
endps